import React, { PropTypes } from 'react'
import { routerRedux } from 'dva/router'
import { connect } from 'dva'
import { Spin } from 'antd'
import ExSelectSearch from '../components/exchange/ex-select-search'
import ExSelectList from '../components/exchange/ex-select-list'
import ExSelectModal from '../components/exchange/ex-select-modal'

function ExChangeSelect({location,	dispatch,app,exselect}) {
	const {list,loading,pagination,modalVisible,modalType,dataSource,detailList} = exselect;

	const exSelectModalProps = {
		visible: modalVisible,
		dataSource: detailList,
		onCancel() {
			dispatch({
				type: 'exselect/hideModal'
			})
		},		
	}
	const exSelectListProps = {
		dataSource: list,
		loading,
		pagination: pagination,
		onEditItem(params){
			dispatch({
				type:'exselect/details',
				payload:{
					exorder_no:params.exorder_no,
				}
			})
		},
		// onPageChange(page) {
  //  		dispatch({
		// 		type: 'exselect/search',
		// 		payload: {
		// 			page: page.current,
		// 			pageSize: page.pageSize
		// 		}
		// 	})
		// },
		onPageChange(page) {
			const { query, pathname } = location;
			dispatch(routerRedux.push({
				pathname: pathname,
				query: {
					...query,
					page: page.current,
					pageSize: page.pageSize
				}
			}))
		},
	}
	
	const exSelectSearchProps= {
		onSearch(params){
			dispatch(routerRedux.push({
        pathname: '/exchange/exselect',
        query: {
          ...params
        },
      }))
   		//dispatch({
			// 	type: 'exselect/search',
			// 	payload: params
			// })

		},		
		onClear(){
			dispatch({
				type: 'exselect/clear'
			})
		}
	}


	const StationModalGen = () =>
		<ExSelectModal { ...exSelectModalProps}/>;
	return( 
		<div className = 'content-inner' >
			<Spin tip = 'loading...' spinning = {loading} size = 'large' >
				<ExSelectSearch {...exSelectSearchProps}/> 				
				<ExSelectList {...exSelectListProps}/>
				{
				<StationModalGen />
				}
			</Spin> 
		</div>
	)
}

ExChangeSelect.propTypes = {
	exselect: PropTypes.object,
	location: PropTypes.object,
	dispatch: PropTypes.func
};

function mapStateToProps({app,exselect}) {
	return {app,exselect	}
}
export default connect(mapStateToProps)(ExChangeSelect)